package com.yanqu.road.dao.impl.activity.operamask;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.operamask.config.OperaMaskSkillConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class OperaMaskSkillConfigDaoImpl extends TempDao {

    private static String getOperaMaskSkillConfigSql = "select * from `t_s_opera_skill` where `activityId`=?";

    public Map<Integer, List<OperaMaskSkillConfig>> getOperaMaskSkillConfigMap(int activityId) {
        Map<Integer, List<OperaMaskSkillConfig>> listMap = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getOperaMaskSkillConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                OperaMaskSkillConfig operaMaskSkillConfig = new OperaMaskSkillConfig();
                operaMaskSkillConfig.setActivityId(rs.getInt("activityId"));
                operaMaskSkillConfig.setSkillId(rs.getInt("skillId"));
                operaMaskSkillConfig.setSkillLevel(rs.getInt("skillLevel"));
                operaMaskSkillConfig.setSkillParam(rs.getString("skillParam"));
                operaMaskSkillConfig.setIcon(rs.getString("icon"));
                listMap.putIfAbsent(operaMaskSkillConfig.getSkillId(), new ArrayList<>());
                listMap.get(operaMaskSkillConfig.getSkillId()).add(operaMaskSkillConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return listMap;
    }

}
